﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Permissions;
using System.Security;

namespace Light.Framework
{
    [Serializable, AttributeUsage(AttributeTargets.Class | AttributeTargets.Method,
         AllowMultiple = false, Inherited = false)]
    public sealed class AccessSecurityAttribute : CodeAccessSecurityAttribute
    {
        private string _taskCodes = null;
        private bool demandAll = false;

        /// <summary>
        /// 是否检验全部权限
        /// </summary>
        public bool DemandAll
        {
            get { return demandAll; }
            set { demandAll = value; }
        }

        public AccessSecurityAttribute(SecurityAction action)
            : base(action)
        {
            this.Unrestricted = true;
        }

        public string TaskCodes
        {
            get
            {
                return _taskCodes;
            }
            set
            {
                _taskCodes = value;
            }
        }

        public override IPermission CreatePermission()
        {
            return new AccessPermission(this.Unrestricted, this.TaskCodes, this.DemandAll);
        }
    }
}
